﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GeoFly
{
    public partial class GridLayerParaDialog : Form
    {
        public GridLayerParaDialog()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            this.textBox_DEM.Text = dlg.FileName;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            this.textBox_LULC.Text = dlg.FileName;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            this.textBox_SOIL.Text = dlg.FileName;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            string filename = dlg.FileName;
            StreamReader sr = new StreamReader(filename);
            //跳过文件表头
            sr.ReadLine();
            //下面开始读数据
            while (!sr.EndOfStream)
            {
                string[] strs = sr.ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);

            }

            
        }

        private void button7_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            if (dlg.ShowDialog() != DialogResult.OK)
                return;
            
        }

        private void button4_Click(object sender, EventArgs e)
        {
            string s= this.textBox_DEM.Text;
            if (s == "")
            {
                MessageBox.Show("DEM文件路径设置不能为空");
                return;
            }
            
            HydroSimulate.g_GridLayerPara.DemFileName = s;
            s = this.textBox_LULC.Text;
            if (s == "")
            {
                MessageBox.Show("LULC文件路径设置不能为空");
                return;
            }
            HydroSimulate.g_GridLayerPara.LulcFileName = s;
            s = this.textBox_SOIL.Text;
            if (s == "")
            {
                MessageBox.Show("SOIL文件路径设置不能为空");
                return;
            }
            HydroSimulate.g_GridLayerPara.SoilFileName = s;

            HydroSimulate.g_GridLayerPara.WriteGridIOFile(HydroSimulate.path + "\\SysPara\\GridIO.txt");

        }

        private void GridLayerParaDialog_Load(object sender, EventArgs e)
        {
            this.textBox_DEM.Text = HydroSimulate.g_GridLayerPara.DemFileName;
            this.textBox_LULC.Text = HydroSimulate.g_GridLayerPara.LulcFileName;
            this.textBox_SOIL.Text = HydroSimulate.g_GridLayerPara.SoilFileName;
        }
    }
}